﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public  class UserOrderDAO:BaseService
    {
        public UserOrder GetUserOrderById(int id)
        {
            return (UserOrder)this.FindModelById("UserOrder",id);
        }

        public bool Add(UserOrder uo)
        {
           return base.Add(uo);
        }

        public UserOrder GetUserOrderByUserId(int userId)
        {
            return base.GetItemByHQL<UserOrder>("from UserOrder where UserId="+userId+"");
        }
        public IList<UserOrder> GetListByStyleAndState(int guimoid, int state, int page, int pagesize)
        {
            string hql = "from UserOrder where 1=1 ";
            if (guimoid != 0)
            {
                hql += " and MystyleId = " + guimoid;
            }
            if (state != 0)
            {
                hql += " and State = " + state;
            }
            hql += " order by AddDate desc";
            try
            {
                return FindList<UserOrder>(hql, null, (page - 1) * pagesize, pagesize);
            }
            catch 
            {

                return null;
            }
        }
        public int GetListByStyleAndState(int guimoid, int state)
        {
            string hql = "select count(*) from UserOrder where 1=1 ";
            if (guimoid != 0)
            {
                hql += " and MystyleId = " + guimoid;
            }
            if (state != 0)
            {
                hql += " and State = " + state;
            }
            
            try
            {
                return Convert.ToInt32(GetValue(hql));
            }
            catch
            {

                return 0;
            }
        }
        public bool EditOrderState(string ids,int state)
        {
            string hql = "update  UserOrder set State = " + state + " where Id in(" + ids + ")";
            try
            {
                DBHelper.TransDeleteByHQL(hql);
                return true;
            }
            catch 
            {

                return false;
            }
        }
    }
}
